<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
               sort() 排序
               */
      (function () {
        var arr2 = [10, 20, 5, 100, 300, 50, 20];
        var resArr2 = arr2.sort();
        console.log(resArr2); //输出  [10, 20, 5, 100, 300, 50, 20];
        //解决问题
        var arr3 = [10, 20, 5, 100, 300, 50, 20];
        arr3.sort(function (a, b) {
          return a - b;
        });
        console.log(arr3); //输出  [5, 10, 20, 20, 50, 100, 300]
      })();
    </script>
  </body>
</html>
